<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <button v-on:click="getEmp">点我访问接口</button>
    <p>{{ message }}</p>
    <button v-on:click="addCount">点我增加count</button>
    <p>count : {{ count }}</p>
    <button v-on:click="addAsyncCount">点我异步增加count</button>
    <p>count : {{ count }}</p>
    <p>todoLength : {{ doneTodosCount }}</p>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'HelloWorld',
      message: '接口信息'
    }
  },
  methods: {
    getEmp () {
      this.$get('/emp/get/7788').then(res => {
        this.message = JSON.stringify(res.data)
      }).catch(() => {
        this.message = 'error!'
      })
    },
    addCount () {
      this.$store.commit('increment')
    },
    addAsyncCount () {
      this.$store.dispatch('incrementAction', 1000)
    }
  },
  computed: mapState({
    count: 'count',
    doneTodosCount () {
      return this.$store.getters.doneTodosCount
    }
  })
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
.hello{
  background: antiquewhite;
}
</style>
